package com.etrans.web.gps.business.report.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.bson.Document;
import org.bson.conversions.Bson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.report.domain.Alarms;
import com.etrans.web.gps.business.report.domain.ResultDocs;
import com.etrans.web.gps.common.MGTemplete;
import com.etrans.web.gps.util.MongodbConfig;
import com.mongodb.BasicDBObject;
import com.mongodb.BasicDBObjectBuilder;

/**
 * 报警热区分析Service
 * 
 * @author fxw
 * @return 经纬度map集合
 */
@Service
public class AlarmHotAnalysisService extends BaseService{
	private final static Logger log = LoggerFactory.getLogger(AlarmHotAnalysisService.class);
	
	public List<ResultDocs> queryAlarmHotAnalysisByTime(HashMap<String, Object> param) throws ParseException {// 根据车辆+颜色查询热区
		BasicDBObject query = new BasicDBObject();
		List<ResultDocs> resultList = new ArrayList<ResultDocs>();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String start_Time = (String) param.get("start_Time");
		String end_Time = (String) param.get("end_Time");
		Date startTime = format.parse(start_Time);
		Date endTime = format.parse(end_Time);
		Integer alarmType =(Integer) param.get("alarmType");
		try {
				Calendar calendar= Calendar.getInstance();
				calendar.setTime(startTime);
				if (start_Time.substring(0,10).equals(end_Time.substring(0,10))) {
					query.put("analyse_date", BasicDBObjectBuilder.start("$gte", startTime).get());
				}else {
					query.put("analyse_date", BasicDBObjectBuilder.start("$gte", startTime).add("$lte", endTime).get());
				}
				query.put("alarm_type", alarmType);
				resultList = MGTemplete.find(MongodbConfig.MONGODB_DB, "hot_alarm_swap", query,ResultDocs.class,true);
		} catch (Exception e) {
			e.printStackTrace();
		}
			return resultList;
	}
}
